package com.smart.electronic.fence.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.smart.electronic.fence.mapper.ElectronicFenceMapper;
import com.smart.electronic.fence.pojo.ElectronicFence;
import com.smart.electronic.fence.service.ElectronicFenceService;
import com.smart.electronic.fence.util.PageResult;
import com.smart.electronic.fence.util.PageUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;

@Service
public class ElectronicFenceServiceImpl implements ElectronicFenceService {

    @Resource
    private ElectronicFenceMapper fenceMapper;

    @Override
    public int add(ElectronicFence fence) {
        fence.setStatus(BigInteger.valueOf(1));
        return fenceMapper.insert(fence);
    }

    @Override
    public int removeById(String layerId) {
        return fenceMapper.deleteById(layerId);
    }

    @Override
    public int editById(ElectronicFence fence) {
        return fenceMapper.updateById(fence);
    }

    @Override
    public ElectronicFence getById(String layerId) {
        return fenceMapper.selectById(layerId);
    }

    @Override
    public ElectronicFence getByName(String fenceName) {
        return fenceMapper.selectByName(fenceName);
    }

    @Override
    public List<ElectronicFence> getAll() {
        return fenceMapper.selectAll();
    }

    @Override
    public PageResult findPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ElectronicFence> fences = fenceMapper.selectAll();
        PageInfo<ElectronicFence> pageInfo=new PageInfo(fences);
        return PageUtils.getPageResult( pageInfo);
    }

    @Override
    public PageResult seachByPage(String fenceName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ElectronicFence> fences = fenceMapper.selectAllBySeach(fenceName);
        PageInfo<ElectronicFence> pageInfo=new PageInfo(fences);
        return PageUtils.getPageResult( pageInfo);
    }
}
